package com.eastfair.point.service.impl;

import com.alibaba.fastjson.JSON;
import com.eastfair.point.UserLoginPoint;
import com.eastfair.core.point.BasePoint;
import com.eastfair.point.dao.TestCollectionDao;
import com.eastfair.point.entity.TestCollection;
import com.eastfair.point.service.TestCollectionService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.ZoneId;
import java.util.Date;

/**
 * <p>
 * 业务实现类
 * 用户账户信息
 * </p>
 *
 * @author ligang
 * @date 2021-08-10
 */
@Slf4j
@Service
public class TestCollectionServiceImpl implements TestCollectionService {
    @Autowired
    TestCollectionDao testCollectionDao;

    @Override
    public void add(BasePoint basePoint) {
        //用户登录事件
        UserLoginPoint userLoginPoint = JSON.toJavaObject((JSON) basePoint.getPointObj(), UserLoginPoint.class);
        TestCollection testCollection = new TestCollection();
        testCollection.setBookId(userLoginPoint.getMsg());
        testCollection.setSchoolId(userLoginPoint.getEmail());
        testCollection.setBookClassification(basePoint.getTrace());
        testCollection.setDate(Date.from(basePoint.getCreateTime().atZone(ZoneId.systemDefault()).toInstant()));
        testCollectionDao.add(testCollection);
    }

}
